package com.chefu.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chefu.admin.pojo.ServiceProvider;
import com.chefu.common.pojo.PageResult;
import com.chefu.server.mapper.ServerMapper;
import com.chefu.server.pojo.Server;
import com.chefu.server.pojo.ServerClassify;
import com.chefu.server.service.ServerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author goodgoodstudy
 * @since 2021-03-30
 */
@Service
public class ServerServiceImpl extends ServiceImpl<ServerMapper, Server> implements ServerService {

    @Autowired
    private ServerMapper serverMapper;


    @Override
    public PageResult<Server> serverQueryPage(Integer pageNum, Integer pageSize,
                                              String serverName, Long code,
                                              String name) {
        //封装分页参数
        IPage<Server> iPage = new Page<>(pageNum,pageSize);

        //封装查询条件
        QueryWrapper<Server> queryWrapper = Wrappers.query();

        //***把需要的条件封装进去QueryWrapper里面去***
        if(StringUtils.isNotEmpty(serverName)){
            queryWrapper.like("",serverName);
        }
        if(code!=null){
            queryWrapper.like("code",code);
        }
        if(StringUtils.isNotEmpty(name)){
            queryWrapper.like("name",name);
        }

        //2.查询数据，获取结果
        iPage = serverMapper.selectPage(iPage,queryWrapper);

        //3.处理(封装)结果
        PageResult<Server> pageResult = new PageResult<>(iPage.getTotal(),iPage.getSize(),iPage.getRecords());

        return pageResult;
    }

    @Override
    public ServiceProvider serviceProviderById(Long id) {

        return null;
    }


}
